Skip to content

Conversation

silva-fj
Copy link

@silva-fj silva-fj commented Sep 15, 2025

Summary

This PR integrates the pallet-contracts module into the Subtensor runtime, enabling wasm smart contract functionality with a custom chain extension for accessing Subtensor-specific features.

Key Features

  1. Custom Chain Extension: The following calls are exposed
    - SubtensorModule::add_stake
    - SubtensorModule::remove_stake
    - SubtensorModule::unstake_all
    - SubtensorModule::unstake_all_alpha
    - SubtensorModule::move_stake
    - SubtensorModule::transfer_stake
    - SubtensorModule::swap_stake
    - SubtensorModule::add_stake_limit
    - SubtensorModule::remove_stake_limit
    - SubtensorModule::swap_stake_limit
    - SubtensorModule::remove_stake_full_limit
    - SubtensorModule::set_coldkey_auto_stake_hotkey
    - Proxy::add_proxy (Staking)
    - Proxy::remove_proxy (Staking)

  2. Restricted Call Filter: Whitelisted operations

    • Proxy::proxy
  3. Conservative Configuration

    • Memory limits: 1GB for runtime, 2GB for validators
    • Maximum code size: 128KB
    • Call stack depth: 5 frames
    • Transient storage: 1MB

Breaking Changes

None - This is an additive change that doesn't affect existing functionality.

@masterdubs
Copy link

This proposal is groundbreaking, it open lot of native doors integration.
As soon as it is merged we will use it in Hippius for alpha handling.

@sam0x17 sam0x17 added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Sep 17, 2025
@silva-fj silva-fj marked this pull request as ready for review September 18, 2025 09:53
@camfairchild
Copy link
Contributor

I saw something in the docs saying the APIs for the extrinsics we allow has to remain stable.

We solve this in the frontier (EVM) pallet by using precompiles with stable APIs but the underlying extrinsics can change.

Possibly we should do the same because I'm not sure if we can guarantee the stability of any of the extrinsics at-present

@camfairchild
Copy link
Contributor

Also, @silva-fj let's actually remove the proxy::create_pure because I'm uncertain how the contract would be able to grab the resultant Pure proxy account that was created. It's only in an event created after the fact

@silva-fj
Copy link
Author

I saw something in the docs saying the APIs for the extrinsics we allow has to remain stable.

We solve this in the frontier (EVM) pallet by using precompiles with stable APIs but the underlying extrinsics can change.

Possibly we should do the same because I'm not sure if we can guarantee the stability of any of the extrinsics at-present

Yes that's correct, the whitelisted dispatchables should remain stable. This is not exactly as critical as on EVM contracts because ink contracts can be upgradable (just like the runtime). But ideally a stable API should be provided.

This can be accomplished with chain extensions, by exposing an API that remains stable while the underlying dispatchables could be changed

@camfairchild
Copy link
Contributor

This is not exactly as critical as on EVM contracts because ink contracts can be upgradable (just like the runtime).

EVM contracts use an upgradeable pattern as well.

This can be accomplished with chain extensions, by exposing an API that remains stable while the underlying dispatchables could be changed

Possibly we can also just agree that the API is not stable and any contracts implementing the calls can check the runtime version to see if it has changed/if their current contract version (self-imposed) supports it.

i.e. like a guard clause

@sam0x17
Copy link
Contributor

sam0x17 commented Oct 7, 2025

are you satisfied with this as is @camfairchild ?

@sam0x17
Copy link
Contributor

sam0x17 commented Oct 7, 2025

just a few tiny merge conflicts

Define chain extension function IDs for staking operations and outcome
codes for error handling
Expose 12 subtensor pallet functions to smart contracts:
- GetStakeInfoForHotkeyColdkeyNetuidV1 (query)
- AddStakeV1, RemoveStakeV1
- UnstakeAllV1, UnstakeAllAlphaV1
- MoveStakeV1, TransferStakeV1, SwapStakeV1
- AddStakeLimitV1, RemoveStakeLimitV1, SwapStakeLimitV1
- RemoveStakeFullLimitV1, SetColdkeyAutoStakeHotkeyV1
Resolved conflicts and updated chain-extensions to align with upstream removal of governance pallets.
Add FunctionId::AddProxyV1 (ID 13) for proxy management and three new
error codes for proxy-specific failures: ProxyTooMany, ProxyDuplicate,
and ProxyNoSelfProxy.
Add pallet-subtensor-proxy to dependencies for proxy chain extension
support.
Add AddProxyV1 chain extension handler that calls pallet_proxy::add_proxy
with ProxyType::Staking and zero delay, matching precompile behavior.
Configure pallet_proxy in mock runtime with ProxyType InstanceFilter
implementation for chain extension tests.
Add test verifying AddProxyV1 creates proxy relationship with correct
delegate, proxy type (Staking), and delay (0).
Document AddProxyV1 function (ID 13) and associated error codes in
contracts documentation.
Remove add_proxy from whitelisted contract calls as it should be called
via chain extension instead of direct runtime call.
Add FunctionId::RemoveProxyV1 (ID 14) and ProxyNotFound error code for
proxy removal failures.
Add RemoveProxyV1 handler that calls pallet_proxy::remove_proxy with
ProxyType::Staking and zero delay, matching add_proxy behavior.
Add test verifying RemoveProxyV1 successfully removes proxy relationship
after it was created with AddProxyV1.
Document RemoveProxyV1 function (ID 14) and ProxyNotFound error code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants